package com.yjt.sousou.integral;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.sousou.R;
import com.yjt.sousou.user.LoginTag;
import com.yjt.sousou.utils.HDPreference;

import java.util.List;

/**
 * 作者：83734
 * 时间：2018/12/1
 * 描述：
 */
public class RankingAdapter extends BaseQuickAdapter<Ranking.DataBean,BaseViewHolder> {

    public RankingAdapter(int layoutResId, @Nullable List<Ranking.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, Ranking.DataBean item) {
        String userId = HDPreference.getUserId(LoginTag.USER_ID.name());
        TextView tv_integral = helper.getView(R.id.tv_integral);
        helper.setText(R.id.tv_num,String.valueOf(item.getXuhao()));
        helper.setText(R.id.tv_name,item.getUsername());
        tv_integral.setText(String.valueOf(item.getWorking_score()));
        helper.setText(R.id.tv_group,"["+item.getFenzu_name()+"]");

        helper.setText(R.id.tv_total_num,String.valueOf(item.getWeixiuliang())+"单");
        helper.setText(R.id.tv_you,String.valueOf(item.getYouping())+"个");
        helper.setText(R.id.tv_gong,String.valueOf(item.getWorking_hours())+"小时");
        helper.setText(R.id.tv_wan,String.valueOf(item.getWanchenglv()));
        helper.setText(R.id.tv_fan,String.valueOf(item.getFanxiulv()));
        if(userId.equals(item.getId())){
            helper.setTextColor(R.id.tv_name, ContextCompat.getColor(mContext,R.color.circle_integral_excellent));
        }else {
            helper.setTextColor(R.id.tv_name,ContextCompat.getColor(mContext,R.color.black));
        }
         LinearLayout relativeLayout = helper.getView(R.id.rl_msg);
         LinearLayout ll_detail = helper.getView(R.id.ll_detail);
        if(item.isClicked()){
            relativeLayout.setBackgroundResource(R.color.blue_bg);
            tv_integral.setTextColor(ContextCompat.getColor(mContext,R.color.white));
            ll_detail.setVisibility(View.VISIBLE);
        }else {
            relativeLayout.setBackgroundResource(R.color.white);
            ll_detail.setVisibility(View.GONE);
            tv_integral.setTextColor(ContextCompat.getColor(mContext,R.color.text_color));
        }
        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < getData().size(); i++) {
                    if(i == helper.getAdapterPosition()){
                        getData().get(i).setClicked(true);
                    }else {
                        getData().get(i).setClicked(false);
                    }
                }
                notifyDataSetChanged();
            }
        });
    }
}
